package com.dodoke.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dodoke.dto.RetailCompanyDTO;
import com.dodoke.entity.RetailCompany;
import com.dodoke.mapper.RetailCompanyMapper;
import com.dodoke.service.IRetailCompanyService;
import com.dodoke.vo.RetailCompanyAllListVO;
import com.dodoke.vo.RetailCompanyVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公司信息业务实现
 */
@Service
public class RetailCompanyServiceImpl extends ServiceImpl<RetailCompanyMapper, RetailCompany> implements IRetailCompanyService {
    @Resource
    private RetailCompanyMapper retailCompanyMapper;

    /**
     * 公司信息分页
     *
     * @param currentPage      当前页码
     * @param pageSize         每页显示条数
     * @param retailCompanyDTO 模糊查询接收参数
     * @return
     */
    @Override
    public Page<RetailCompanyVO> getListByPage(Integer currentPage, Integer pageSize, RetailCompanyDTO retailCompanyDTO) {
        // 查询使用xml,分页使用mp
        Page<RetailCompanyVO> page = new Page<>(currentPage, pageSize);
        Page<RetailCompanyVO> retailCompanyVOPage = retailCompanyMapper.selectByList(page, retailCompanyDTO);
        return retailCompanyVOPage;
    }

    /**
     * 新增公司信息
     *
     * @param retailCompany
     * @return
     */
    @Override
    public int addRetailCompany(RetailCompany retailCompany) {
        retailCompany.setDelFlag("0");
        return retailCompanyMapper.insertRetailCompany(retailCompany);
    }

    /**
     * 修改公司信息
     *
     * @param retailCompany
     * @return
     */
    @Override
    public int editRetailCompany(RetailCompany retailCompany) {
        return retailCompanyMapper.updateRetailCompany(retailCompany);
    }

    /**
     * 根据id获取公司信息
     *
     * @param id
     * @return
     */
    @Override
    public RetailCompanyVO getRetailCompanyById(Long id) {
        RetailCompany retailCompany = retailCompanyMapper.selectById(id);
        RetailCompanyVO retailCompanyVO = JSON.parseObject(JSON.toJSONString(retailCompany), RetailCompanyVO.class);
        return retailCompanyVO;
    }

    /**
     * 获取公司所有列表
     *
     * @return
     */
    @Override
    public List<RetailCompanyAllListVO> getRetailCompanyAllList() {
        return retailCompanyMapper.selectAllList();
    }
}
